package org.snia.cdmi.rs.provider;

import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;

import org.snia.cdmi.exception.InternalException;

/**
 * <p>Map {@link InternalException} to an HTTP Status 500 response.</p>
 */
@Provider
public class InternalExceptionMapper extends AbstractExceptionMapper
    implements ExceptionMapper<InternalException>
{
    @Override
    public Response toResponse(InternalException e) {
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
                .type(MediaType.TEXT_PLAIN_TYPE)
                .entity(getText(e))
                .build();
    }

}